<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>Objcet.definePropentry1</title>
  <!-- 引入Vue -->
  <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
  <!-- 准备好一个容器-->
  <div id="demo">

  </div>
</body>

<script type="text/javascript">
  let obj = {
    name: '马志强',
    sex: '男'
  }

  Object.defineProperty(obj, 'age', {
    // 当有人访问对象中的属性时,get方法就会被调用
    get() {
      console.log(1111);
      return 66
    },
    set() {
      // 当有人修改对象中的属性时,set方法就会被调用
      console.log(22222);
    }
  })
  obj.age = 60
  obj.age = 502
  console.log(obj.name);
  console.log(obj.age);
  console.log(obj.sex);
</script>

</html>